package cn.bornsoft.mobileServer.db;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

/**
 * A data access object (DAO) providing persistence and search support for
 * BcNewsclass entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see cn.bornsoft.mobileServer.db.BcNewsclass
 * @author MyEclipse Persistence Tools
 */

public class BcNewsclassDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(BcNewsclassDAO.class);
	// property constants
	public static final String CLASSCNAME = "classcname";
	public static final String CLASSENAME = "classename";
	public static final String CONTENT = "content";
	public static final String PARENTID = "parentid";
	public static final String CLASSTEMP = "classtemp";
	public static final String NEWSTEMP = "newstemp";
	public static final String SAVEFILEPATH = "savefilepath";
	public static final String FILEEXTNAME = "fileextname";
	public static final String DOMAIN = "domain";
	public static final String CLASSIFY = "classify";

	public void save(BcNewsclass transientInstance) {
		log.debug("saving BcNewsclass instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(BcNewsclass persistentInstance) {
		log.debug("deleting BcNewsclass instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public BcNewsclass findById(java.lang.String id) {
		log.debug("getting BcNewsclass instance with id: " + id);
		try {
			getSession().clear();// 清除查询缓存

			BcNewsclass instance = (BcNewsclass) getSession().get(
					"cn.bornsoft.mobileServer.db.BcNewsclass", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(BcNewsclass instance) {
		log.debug("finding BcNewsclass instance by example");
		try {
			List results = getSession().createCriteria(
					"cn.bornsoft.mobileServer.db.BcNewsclass").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding BcNewsclass instance with property: " + propertyName
				+ ", value: " + value);
		try {
			getSession().clear();// 清除查询缓存
			String queryString = "from BcNewsclass as model where model."
					+ propertyName + "= ? order by model.orders asc,model.addtime desc";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByClasscname(Object classcname) {
		return findByProperty(CLASSCNAME, classcname);
	}

	public List findByClassename(Object classename) {
		return findByProperty(CLASSENAME, classename);
	}

	public List findByContent(Object content) {
		return findByProperty(CONTENT, content);
	}

	public List findByParentid(Object parentid) {
		return findByProperty(PARENTID, parentid);
	}

	public List findByClasstemp(Object classtemp) {
		return findByProperty(CLASSTEMP, classtemp);
	}

	public List findByNewstemp(Object newstemp) {
		return findByProperty(NEWSTEMP, newstemp);
	}

	public List findBySavefilepath(Object savefilepath) {
		return findByProperty(SAVEFILEPATH, savefilepath);
	}

	public List findByFileextname(Object fileextname) {
		return findByProperty(FILEEXTNAME, fileextname);
	}

	public List findByDomain(Object domain) {
		return findByProperty(DOMAIN, domain);
	}

	public List findByClassify(Object classify) {
		return findByProperty(CLASSIFY, classify);
	}

	public List findAll() {
		log.debug("finding all BcNewsclass instances");
		try {
			String queryString = "from BcNewsclass";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public BcNewsclass merge(BcNewsclass detachedInstance) {
		log.debug("merging BcNewsclass instance");
		try {
			BcNewsclass result = (BcNewsclass) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(BcNewsclass instance) {
		log.debug("attaching dirty BcNewsclass instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(BcNewsclass instance) {
		log.debug("attaching clean BcNewsclass instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}